package com.baosu.controller.back;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.api.R;
import com.baosu.domain.Result;
import com.baosu.domain.User;
import com.baosu.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.DigestUtils;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@RestController
@Api(tags = "用户接口")
public class UserController {

    @Autowired
    private UserService userService;

    @PostMapping("/login")
    @ApiOperation(value = "登录")
    public Result login(HttpServletRequest request, @RequestBody User user){
        return userService.login(request,user);
    }

    @PutMapping("/updatePwd")
    @ApiOperation(value = "修改密码")
    public Result updatePwd(@RequestBody Map map){
        return userService.updatePwd(map.get("oldPwd").toString(), map.get("newPwd").toString());
    }

    @PostMapping("/logout")
    @ApiOperation(value = "注销")
    public Result logout(HttpServletRequest request){
        request.getSession().removeAttribute("user");
        return Result.ok(null).message("注销成功");
    }

}
